//
// Created by lenovo on 2024/8/12.
//

#ifndef TREELIB_TREE_MULTITREE_DENSETREE_H
#define TREELIB_TREE_MULTITREE_DENSETREE_H
#include "./TemplateNode.h"
#include "./TemplateTree.h"

namespace TREE{
    template <typename T>
    class DenseNode : public TemplateNode<T>{
    public:
        DenseNode(T data) {this->_data = data ;}
        bool _acceptable (Node<T>* node) override ;
        void setChild (T data , int n ) override ;
        void setChild (Node<T>* node , int n ) override ;
    };

    template<typename T>
    void DenseNode<T>::setChild(Node<T> *node, int n) {
        if (not _acceptable(node))
            return ;

//        cout << "(pos , width) = ( " << n << " , " << this->width() << " ) " << endl ;
        if (n >= this->width()){
//            cout << "push back" << endl ;
            this->_nodes.push_back(node);
        }else{
//            cout << "normal setting " << endl ;
            this->_nodes[n] = node ;
        }

    }

    template<typename T>
    void DenseNode<T>::setChild(T data, int n) {
        setChild(new DenseNode<T>(data) , n);
    }

    template<typename T>
    bool DenseNode<T>::_acceptable(Node<T> *node) {
        return node ;//node != null
    }

    template <typename T>
    using DenseTree = TemplateTree<DenseNode<T> > ;
}


#endif //TREELIB_TREE_MULTITREE_DENSETREE_H
